﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using System.Xml.Serialization;
using TappUpsRefresh.Extras;

namespace SlXnaApp3
{
    public partial class ScorePage : PhoneApplicationPage
    {
        List<Score> scores = new List<Score>();
        public ScorePage()
        {
            InitializeComponent();                                                          
            IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
            XmlSerializer xmls = new XmlSerializer(typeof(Score));
            String[] list  = isf.GetFileNames("*.score");

           
            foreach (String str in list)
            {
                using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(str, System.IO.FileMode.Open, isf))
                {
                    try
                    {
                        Score temp = (Score)xmls.Deserialize(isfs);
                        scores.Add(temp);
                        isfs.Close();
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("An internal Error occured! We are sorry but some of your scores may not get loaded");
                        //isf.DeleteFile(str);
                    }
                }                
            }
        }

        private void listBox1_Loaded(object sender, RoutedEventArgs e)
        {
            foreach (Score score in scores)
                if (score.Difficulty == "Easy")
                    listBox1.Items.Add(score);
        }

        private void listBox2_Loaded(object sender, RoutedEventArgs e)
        {
            foreach (Score score in scores)
                if (score.Difficulty == "Difficult")
                    listBox2.Items.Add(score);
        }

        private void listBox1_Loaded_1(object sender, RoutedEventArgs e)
        {

        }

        private void appbar_button1_Click(object sender, EventArgs e)
        {
            Microsoft.Phone.Tasks.ShareStatusTask a = new Microsoft.Phone.Tasks.ShareStatusTask();
            a.Show();
        }

        private void Delete_Click(object sender, RoutedEventArgs e)
        {
            //Do something :P
        }

        
    }
}